package com.xxx.common.controller;


import com.github.pagehelper.PageInfo;
import com.xxx.common.entity.Project;
import com.xxx.common.service.ProjectService;
import com.xxx.common.utils.Result;
import com.xxx.common.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 */
@RestController
@RequestMapping("/common/project")
public class ProjectController {
    
    @Autowired
    private ProjectService projectService;

    @GetMapping("/getProjectInfo")
    public Result getProjectInfo(Project Project, @RequestParam(value="pageNum",defaultValue = "1") Integer pageNum,
                              @RequestParam(value="pageSize",defaultValue = "10") Integer pageSize){
        try{
            PageInfo<Project> data = projectService.selectProjectInfo(Project,pageNum,pageSize);
            return ResultUtil.success(1,"成功",data);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.error(-1,"失败");
        }
    }

    @PostMapping("/saveAndUpdateProjectInfo")
    public Result saveAndUpdateProjectInfo(Project Project){
        try {
            Integer count = projectService.saveAndUpdateProjectInfo(Project);
            return ResultUtil.success(1,"成功",count);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.error(-1,"失败");
        }
    }

    @DeleteMapping("/delProjectInfo")
    public Result delProjectInfo(Integer id){
        try {
            Integer count = projectService.delProjectInfo(id);
            return ResultUtil.success(1,"成功",count);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.error(-1,"失败");
        }
    }


}

